package user_role_v1

import (
	"context"
	"errors"
	"gf-xb-api/internal/consts"
	"gf-xb-api/internal/dao"
	"gf-xb-api/utility/xpermission"

	"github.com/gogf/gf/v2/frame/g"
)

func (s *sUserRole) Disable(ctx context.Context, ids []uint) (err error) {
	// 参数检查
	if len(ids) == 0 {
		return errors.New("Id数组不能为空")
	}

	cols := dao.SysUserRole.Columns()
	userUUID := xpermission.GetLoginUserUUID(ctx)

	m := dao.SysUserRole.Ctx(ctx).Data(g.Map{
		cols.Status:    uint(consts.STATUS_INACTIVE),
		cols.UpdatedBy: userUUID,
	})

	if len(ids) == 1 {
		m = m.WherePri(ids[0])
	} else {
		m = m.WhereIn(cols.Id, ids)
	}

	_, err = m.Update()
	return err
}
